package comparable;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

public class Comparable_ {
    public static void main(String[] args) {
        Person p1 = new Person("zhangsan", 20);
        Person p2 = new Person("lisi", 18);
        Person p3 = new Person("wangwu", 25);

        Person[] persons = { p1, p2, p3 };
        System.out.println("排序前");
        for (Person person : persons) {
            System.out.println(person.name + ":" + person.age);
        }
        // Arrays是数组工具类，Collections是集合工具类
        Arrays.sort(persons);
        System.out.println("排序后");
        for (Person person : persons) {
            System.out.println(person.name + ":" + person.age);
        }

        ArrayList<Person> list = new ArrayList<Person>();
        list.add(p1);
        list.add(p2);
        list.add(p3);
        System.out.println(list);
        Collections.sort(list);
        System.out.println(list);
    }
}
